package MyTCP;

import java.io.DataOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.net.Socket;
import java.util.Scanner;

public class MyClient {
    //TCP 实现多发多收
    public static void main(String[] args) throws IOException {
        //创建管道对象
        Socket socket = new Socket("127.0.0.1",8888);
        //获取写数据流
        OutputStream os = socket.getOutputStream();
        //将低级流转换为高级流
        DataOutputStream dos = new DataOutputStream(os);
        Scanner scanner = new Scanner(System.in);

        while (true) {
            String msg = scanner.nextLine();
            if ("exit".equals(msg)){
                System.out.println("退出成功!!!!");
                //关闭资源
                dos.close();
                socket.close();
                break;
            }
            //写数据
            dos.writeUTF(msg);
            //刷新数据，将缓存的数据进行刷新
            dos.flush();
        }
    }
}


